﻿using IceDog.DNF.Program.Mvc5.Models;
using System.Collections.Generic;
using System.Data.Entity;

namespace IceDog.DNF.Program.Mvc5.EfContext
{
    public class AccountInitializer : DropCreateDatabaseIfModelChanges<AccountContext>
    {
        protected override void Seed(AccountContext context)
        {
            var users = new List<SystemUser>()
            {
                new SystemUser()
                {
                    UserName="Admin",
                    Password="123456",
                    Email="Alice@qq.com"
                },
                new SystemUser()
                {
                    UserName="Alice",
                    Password="123456",
                    Email="Alice@qq.com"
                },
                new SystemUser()
                {
                    UserName="Ben",
                    Password="123456",
                    Email="Ben@qq.com"
                }
            };
            var roles = new List<SystemRole>()
            {
                new SystemRole()
                {
                    RoleName="Administrator",
                    RoleDescription="Administrator have full authorization to perform system administration."
                },
                new SystemRole()
                {
                    RoleName="General User",
                    RoleDescription="General User can access the data they are authorized for."
                }
            };
            var systemUserRoles = new List<SystemUserRole>()
            {
                new SystemUserRole()
                {
                    SystemUserId = 1,
                    SystemRoleId = 1
                },
                new SystemUserRole()
                {
                    SystemUserId = 2,
                    SystemRoleId = 2
                },
                new SystemUserRole()
                {
                    SystemUserId = 3,
                    SystemRoleId = 21
                },
            };
            context.SystemUsers.AddRange(users);
            context.SystemRoles.AddRange(roles);
            context.SaveChanges();
        }
    }
}